(function (_this) {
    if (typeof SiteConfig == "undefined") {
        SiteConfig = {}
    }
    _this.TemplateList = $.extend(true, _this.TemplateList, _this.ProjectTemplateList);
    //页面渲染
    _this.Render = function (options) {
        var __this = new Object();
        var __config = {
            id: "",//渲染容器ID
            componentID: "",//组件名称
            templateID: "",//模板名称
            template: "",//自定义模板内容
            isPage:false,//是否为当前文件夹
            data: null,//数据源
        }
        __config = $.extend(true, __config, options);

        if (__config.templateID == "") {
            __config.templateID = __config.componentID;
        }


        var getId = function (id) {
            return document.querySelector(id);
        }
        var getTemplate = function (id, con) {
            var temp = '';
            if (_this.TemplateList[id]) {
                temp = _this.TemplateList[id]
            }
            if (con != '') {
                temp = con;
            }
            return temp;
        }
        var getComponentPath = function (id,isPage) {
            var ComponentPath = '';
            var ComponentList = {
                Input: SiteConfig.ScriptUrl + 'Component/Input.jsx',
                Tree: SiteConfig.ScriptUrl + 'Component/Tree.jsx',
            }
            if (ComponentList[id]) {
                ComponentPath = ComponentList[id];
            } else {
                if (__config.isPage && !isPage) {
                    ComponentPath = id+'.jsx';
                } else {
                    ComponentPath = SiteConfig.ScriptUrl + 'Component/' + id + '.jsx';
                }


            }
            return ComponentPath;
        }

        // require(["../../Frameweb/FrameScripts/vui.2.0/plugin/require/text!" + getComponentPath(__config.componentID)], function (code) {
        //     var mountNode = getId(__config.id);
        //     var mountTemplate = getTemplate(__config.templateID, __config.template);
        //     var mountData = __config.data;
        //     code += ' const mountTemplate=' + mountTemplate + ';ReactDOM.render(mountTemplate, mountNode);';
        //     code = Babel.transform(code, {presets: ["es2015", "react", "stage-2"]}).code;
        //     // console.log(code)
        //     eval(code);
        // });
        var requireList =[
            //"../../Frameweb/FrameScripts/vui.2.0/plugin/require/text!" + getComponentPath("List",true),
            SiteConfig.FrameworkScriptUrl + "vui.2.0/plugin/require/text!" + getComponentPath(__config.componentID)
        ];
        console.log(requireList);
        require(requireList, function () {
            for(var i=0;i<arguments.length;i++) {
                var code = arguments[i];
                var mountNode = getId(__config.id);
                var mountTemplate = getTemplate(__config.templateID, __config.template);
                var mountData = __config.data;
                if(i==arguments.length-1) {
                    code += ' const mountTemplate=' + mountTemplate + ';ReactDOM.render(mounTetmplate, mountNode);';
                }else{
                    code += ' const mountTemplate=' + mountTemplate;
                }
                code = Babel.transform(code, {presets: ["es2015", "react", "stage-2"]}).code;
                // console.log(code)
                eval(code);
            }
        });
        return __this;
    };
})(vui);
